package cn.yexiaofeng.bookmanager.service;


import cn.yexiaofeng.bookmanager.beans.LendList;
import cn.yexiaofeng.bookmanager.dao.BookInfoMapper;
import cn.yexiaofeng.bookmanager.dao.LendListMapper;
import cn.yexiaofeng.bookmanager.dao.ReaderInfoMapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 借阅
 */
@Service
public class LendListServiceImpl implements  LendListService{

    @Autowired
    BookInfoMapper bookInfoMapper;

    @Autowired
    ReaderInfoMapper readerInfoMapper;

    @Autowired
    LendListMapper lendListMapper;



    @Override
    public List<LendList> getLendInfo(String currPage, String pageSize) {
        PageHelper.startPage(Integer.parseInt(currPage),Integer.parseInt(pageSize));
        List<LendList> lendInfo = lendListMapper.getLendInfo();
        List list=new ArrayList();
        for(LendList lendList:lendInfo){
            Map map=new HashMap();
            map.put("booksInfo",bookInfoMapper.getBookById(lendList.getBook_id()));
            map.put("readerInfo",readerInfoMapper.getReaderInfo(lendList.getReader_id()));
            map.put("lendInfo",lendList);
            list.add(map);
        }

        return list;
    }
}